package com.realbrand.net.realbrandpay.ui.activity.wallet.set;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.LinearLayout;

import com.realbrand.net.realbrandpay.R;
import com.realbrand.net.realbrandpay.base.BaseActivity;
import com.realbrand.net.realbrandpay.db.DBManger;
import com.realbrand.net.realbrandpay.ui.activity.login.LoginActivity;
import com.realbrand.net.realbrandpay.ui.activity.wallet.WalletActivity;
import com.realbrand.net.realbrandpay.untils.Constant;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/9/11.
 */

public class SettingActivity extends BaseActivity {
    @BindView(R.id.settingActivity_toolbar)
    Toolbar settingActivityToolbar;
    @BindView(R.id.settingActivity_line_passwordManage)
    LinearLayout settingActivityLinePasswordManage;
    @BindView(R.id.settingActivity_line_useSetting)
    LinearLayout settingActivityLineUseSetting;
    @BindView(R.id.settingActivity_line_about)
    LinearLayout settingActivityLineAbout;
    @BindView(R.id.settingActivity_line_loginOut)
    LinearLayout settingActivityLineLoginOut;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ButterKnife.bind(this);
        settingActivityToolbar.setTitle("");
        settingActivityToolbar.setNavigationIcon(R.mipmap.ic_back);
        setSupportActionBar(settingActivityToolbar);
        settingActivityToolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(SettingActivity.this, WalletActivity.class));
                finish();
            }
        });
        setOnClick();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.settingactivity_layout;
    }

    @Override
    protected void setOnClick() {
        settingActivityLinePasswordManage.setOnClickListener(this);
        settingActivityLineAbout.setOnClickListener(this);
        settingActivityLineLoginOut.setOnClickListener(this);
        settingActivityLineUseSetting.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            //关于
            case R.id.settingActivity_line_about:
                startActivity(new Intent(this, AboutActivity.class));
                break;
            //登出
            case R.id.settingActivity_line_loginOut:
                startActivity(new Intent(this, WalletLogoutActivity.class));
                new DBManger(this).deleteSQL();
                LoginActivity.isLogin = false;
                SharedPreferences sharedPreferences = getSharedPreferences(Constant.shareName, MODE_PRIVATE);
                SharedPreferences.Editor edit = sharedPreferences.edit();
                edit.clear();
                edit.commit();
                finish();
                break;
            //密码管理
            case R.id.settingActivity_line_passwordManage:
                startActivity(new Intent(this, PasswordManageActivity.class));
                finish();
                break;
            //通用设置
            case R.id.settingActivity_line_useSetting:
                break;
        }
    }
}
